package com.trkj.focusonzhuzhou;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class GuidePagerAcivity extends FragmentActivity{

	private ViewPager vp; 
    private Fragment[] fg = {new GuidePage1Fragment(), 
            new GuidePage2Fragment(), 
            new GuidePage3Fragment(), 
            new GuidePage4Fragment()}; 
    private ImageView[] imgs = new ImageView[4]; 
    
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.vp_guide);
		
		getActionBar().hide();
		vp = (ViewPager) findViewById(R.id.vp); 
        
        imgs[0] = (ImageView) findViewById(R.id.dot1); 
        imgs[1] = (ImageView) findViewById(R.id.dot2); 
        imgs[2] = (ImageView) findViewById(R.id.dot3); 
        imgs[3] = (ImageView) findViewById(R.id.dot4); 
        
        MyViewPager adopter = new MyViewPager(getSupportFragmentManager()); 
        vp.setAdapter(adopter); 
         
        PageChangeListener listener = new PageChangeListener(); 
         
        for (int i = 0; i < imgs.length; i ++) { 
            imgs[i].setOnClickListener(listener); 
        } 
         
        vp.setOnPageChangeListener(new OnPageChangeListener() { 
            @Override 
            public void onPageSelected(int arg0) { 
                for (int i = 0; i < imgs.length; i ++) { 
                    imgs[i].setImageResource(R.drawable.circle_white); 
                } 
                imgs[arg0].setImageResource(R.drawable.circle_blue); 
            } 
             
            @Override 
            public void onPageScrolled(int arg0, float arg1, int arg2) { 
                 
            } 
             
            @Override 
            public void onPageScrollStateChanged(int arg0) { 
                 
            } 
        }); 
	}
	
	class PageChangeListener implements OnClickListener{ 

        @Override 
        public void onClick(View v) { 
            int id = v.getId(); 
            switch (id) { 
                case R.id.dot1: 
                    vp.setCurrentItem(0); 
                    break; 
                case R.id.dot2: 
                    vp.setCurrentItem(1); 
                    break; 
                case R.id.dot3: 
                    vp.setCurrentItem(2); 
                    break; 
                case R.id.dot4: 
                    vp.setCurrentItem(3); 
                    break; 
     
                default: 
                    break; 
            } 
        } 
         
    } 
	
	class MyViewPager extends FragmentPagerAdapter{ 

        public MyViewPager(FragmentManager fm) { 
            super(fm); 
        } 

        @Override 
        public Fragment getItem(int arg0) { 
            return fg[arg0]; 
        } 

        @Override 
        public int getCount() { 
            return fg.length; 
        } 
         
    } 
	
}
